import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'



/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
	{
		path: '/login',
		component: () => import('@/views/login/index'),
		hidden: true
	},

	{
		path: '/404',
		component: () => import('@/views/404'),
		hidden: true
	},
	// 左上角标题
	{
		path: '/',
		component: Layout,
		redirect: '/dash_board',
		children: [{
			path: 'dash_board',
			name: '实验楼管理系统',
			component: () => import('@/views/dashboard/index'),
			meta: { title: '实验楼管理系统', icon: 'lab' }
		}]
	},
	// 这里直接定义路由
	{
		path: '/User',
		component: Layout,
		// redirect: '/user/table',
		name: 'User',
		meta: { title: '用户', icon: 'user' },
		children: [
			{
				path: 'table',
				name: 'Table',
				component: () => import('@/views/user/user'),
				meta: { title: '用户管理', icon: 'table' }
			},
			{
				path: 'add_user',
				name: 'AddUser',
				component: () => import('@/views/user/add_user'),
				meta: { title: '新增用户', icon: 'table' }
			},
			{
				path: 'tree',
				name: 'Tree',
				component: () => import('@/views/tree/index'),
				meta: { title: '用户申诉', icon: 'tree' }
			}
		]
	},


	{
		path: '/form',
		component: Layout,
		name: 'Form',
		meta: { title: '课程', icon: 'form' },
		children: [
			{
				path: 'course',
				name: 'Course',
				component: () => import('@/views/form/course'),
				meta: { title: '课程管理', icon: 'form' }
			},
			{
				path: 'add_course',
				name: 'AddCourse',
				component: () => import('@/views/form/add_course'),
				meta: { title: '新增课程', icon: 'form' }
			},
			{
				path: 'dustbin',
				name: 'Dustbin',
				component: () => import('@/views/form/dustbin'),
				meta: { title: '回收站', icon: 'form' }
			}
		]
	},
	{
		path: '/seckill',
		component: Layout,
		name: 'Seckill',
		meta: { title: '活动', icon: 'form' },
		children: [
			{
				path: 'seckill',
				name: 'Seckill',
				component: () => import('@/views/seckill/seckills'),
				meta: { title: '活动管理', icon: 'form' }
			},
			{
				path: 'add_path',
				name: 'AddPath',
				component: () => import('@/views/seckill/add_seckill'),
				meta: { title: '新增活动', icon: 'form' }
			},
			{
				path: 'camp',
				name: 'Camp',
				component: () => import('@/views/seckill/camp'),
				meta: { title: '库存管理', icon: 'form' }
			},
			{
				path: 'dustbin',
				name: 'Dustbin',
				component: () => import('@/views/seckill/path_dustbin'),
				meta: { title: '回收站', icon: 'form' }
			}
		]
	},
	
	{
		path: '/path',
		component: Layout,
		name: 'Path',
		meta: { title: '路径', icon: 'form' },
		children: [
			{
				path: 'paths',
				name: 'Paths',
				component: () => import('@/views/path/paths'),
				meta: { title: '路径管理', icon: 'form' }
			},
			{
				path: 'add_path',
				name: 'AddPath',
				component: () => import('@/views/path/add_path'),
				meta: { title: '新增路径', icon: 'form' }
			},
			{
				path: 'dustbin',
				name: 'Dustbin',
				component: () => import('@/views/path/path_dustbin'),
				meta: { title: '回收站', icon: 'form' }
			}
		]
	},

	{
		path: '/info',
		component: Layout,
		name: 'Info',
		meta: { title: '消息', icon: 'info' },
		children: [
			{
				path: 'single',
				name: 'Single',
				component: () => import('@/views/info/single'),
				meta: { title: '单人发送', icon: 'info' }
			},
			{
				path: 'multiple',
				name: 'Multiple',
				component: () => import('@/views/info/multiple'),
				meta: { title: '群发消息', icon: 'info' }
			},
		]
	},

	{
		path: '/nested',
		component: Layout,
		redirect: '/nested/menu1',
		name: 'Nested',
		meta: {
			title: 'Nested',
			icon: 'nested'
		},
		children: [
			{
				path: 'menu1',
				component: () => import('@/views/nested/menu1/index'), // Parent router-view
				name: 'Menu1',
				meta: { title: 'Menu1' },
				children: [
					{
						path: 'menu1-1',
						component: () => import('@/views/nested/menu1/menu1-1'),
						name: 'Menu1-1',
						meta: { title: 'Menu1-1' }
					},
					{
						path: 'menu1-2',
						component: () => import('@/views/nested/menu1/menu1-2'),
						name: 'Menu1-2',
						meta: { title: 'Menu1-2' },
						children: [
							{
								path: 'menu1-2-1',
								component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
								name: 'Menu1-2-1',
								meta: { title: 'Menu1-2-1' }
							},
							{
								path: 'menu1-2-2',
								component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
								name: 'Menu1-2-2',
								meta: { title: 'Menu1-2-2' }
							}
						]
					},
					{
						path: 'menu1-3',
						component: () => import('@/views/nested/menu1/menu1-3'),
						name: 'Menu1-3',
						meta: { title: 'Menu1-3' }
					}
				]
			},
			{
				path: 'menu2',
				component: () => import('@/views/nested/menu2/index'),
				meta: { title: 'menu2' }
			}
		]
	},

	{
		path: 'external-link',
		component: Layout,
		children: [
			{
				path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
				meta: { title: 'External Link', icon: 'link' }
			}
		]
	},

	// 404 page must be placed at the end !!!
	{ path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
	mode: 'history', // require service support
	scrollBehavior: () => ({ y: 0 }),
	routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
	const newRouter = createRouter()
	router.matcher = newRouter.matcher // reset router
}

export default router
